<template>
	<view class="disalog-box">
		<view class="disalog-content">
			<view class="disalog-title">绑定手机</view>
			<input class="input" @input="inputChange" placeholder="请输入你的手机号码" type="number" :value="phone" maxlength="13" />
			<view class="button" @click="confirm">
				确认绑定
			</view>
		</view>
	</view>
</template>

<script>
	import * as api from '@/utils/api.js';
	export default {
		props:{
			userinfo:{ // 用户登录信息
				type:Object,
				default:{}
			},
			wxinfo:{ // 微信用户凭证信息
				type:Object,
				default:{}
			},
		},
		data() {
			return {
				phone:''
			}
		},
		methods: {
			inputChange:function(e){
				this.phone = e.detail.value;
			},
			confirm:function(){
				let that = this;
				let userinfo = getApp().globalData.userInfo;
				let phone = this.phone;
				if(!(/^1[3456789]\d{9}$/.test(phone))){
						uni.showToast({
							title: '输入手机号码有误',
							icon:'none',
							duration: 2000
						});
					return;
				}
				let wxinfo = this.wxinfo;
				let employeeId = null;
				// userinfo.employee.forEach(res=>{
				// 	if(res.isDefault == "0"){
				// 		employeeId = res.employeeId;
				// 	}
				// })
				const wxUser = uni.getStorageSync('wxUser');
				console.log('wxUser---->>>>>>>', wxUser)
				console.log('userinfo>>>>>>>', userinfo)
				console.log('getApp().globalData>>>>>>>', getApp().globalData)
				let obj = {
					// employeeId:employeeId,
					mobile:phone,
					wxUserId: wxUser.userId,
					openUserId: wxUser.open_userid,
					wxCorpId: wxUser.corpId
				}
				api.bindWxUser(obj).then(res=>{
					that.getUserInfo();
					uni.showToast({
						title: '绑定手机成功',
						duration: 2000
					});
					this.$emit('close');
				})
			},
			getUserInfo:function(){
				api.user({}).then(res=>{
					console.log('user',res.data);
					that.globalData.userInfo = res.data;
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.disalog-box{
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		height: 100vh;
		background:rgba(0,0,0,0.6);
		.disalog-content{
			box-sizing: border-box;
			padding: 20rpx;
			position: absolute;
			border-radius:10rpx;
			top:50%;
			left:50%;
			width:90%;
			background-color: white;
			transform:translate(-50%,-50%);
			.disalog-title{
				font-size: 28rpx;
				text-align: center;
			}
			.input{
				line-height: 70rpx;
				margin-top: 30rpx;
				height: 70rpx;
				box-sizing: border-box;
				padding: 0 10rpx;
				border-radius: 10rpx;
				border:1px solid #d9d9d9;
				font-size: 28rpx;
			}
			.button{
				font-size: 28rpx;
				margin-top:20rpx;
				text-align: center;
				color: white;
				border-radius: 10rpx;
				background-color: #3190ee;
				line-height: 60rpx;
			}
		}
	}
</style>
